<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        <ul>
          <li v-for="user in users" v-if="user.age>=20">{{user.name}}</li>
        </ul>

        <ul>
          <li v-for="user in newUsers">{{user.name}}</li>
        </ul>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      /*
      1. v-for 的优先级高于v-if
      2. v-for 将所有节点创建好，然后使用 v-if 判断，决定保留还是删除
      3. 不推荐一起使用，可以是用计算属性替代
      */
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          users: [
            { name: "jack", age: 20, gender: 1 },
            { name: "lili", age: 21, gender: 2 },
            { name: "lucy", age: 18, gender: 2 },
            { name: "tom", age: 19, gender: 1 },
          ],
        },
        computed: {
          newUsers() {
            return this.users.filter((el) => el.age >= 20);
          },
        },
      });
    </script>
  </body>
</html>
